package us.gaaoc.framework.webapp.backingbeans.admin;

import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;

import javax.sql.DataSource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.impl.SessionFactoryImpl;
import org.springframework.beans.factory.annotation.Autowired;

import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

public class SystemMonitor extends BaseBackingBean {
	
	/**
	 * Properties
	 */
	private Date systemDate;
	private String systemTime;
	private String javaVersion;
	private String javaVendor;
	private String jvmVersion;
	private String jvmVendor;
	private String javaRuntime;
	private String javaVM;
	private String userName;
	private String osArchitecture;
	private String appServer;
	private String osName; 
	
	@Autowired
	private SessionFactory sessionFactory; 
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	/**
	 * Constructor
	 *
	 */
	public SystemMonitor() {}

	
	
	/**
	 * Getter for property osName
	 * @return osName
	 */
	public String getOsName() {
		OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
		this.osName = osMXBean.getName() + osMXBean.getVersion();
		return this.osName;
	}

	/**
	 * Setter for property osName
	 * @param osName
	 */
	public void setOsName(String osName) {
		this.osName = osName;
	}

	/**
	 * Getter for property appServer
	 * @return appServer
	 */
	public String getAppServer() {
		return appServer;
	}

	/**
	 * Setter for property appServer
	 * @param appServer
	 */
	public void setAppServer(String appServer) {
		this.appServer = appServer;
	}

	/**
	 * Getter for property javaRuntime
	 * @return javaRuntime
	 */
	public String getJavaRuntime() {
		RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
		this.javaRuntime = runtimeMXBean.getName();
		return this.javaRuntime;
	}

	/**
	 * Setter for property javaRuntime
	 * @param javaRuntime
	 */
	public void setJavaRuntime(String javaRuntime) {
		this.javaRuntime = javaRuntime;
	}

	/**
	 * Getter for property javaVendor
	 * @return javaVendor
	 */
	public String getJavaVendor() {
		RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
		this.javaVendor = runtimeMXBean.getSpecVendor();
		return this.javaVendor;
	}

	/**
	 * Setter for property javaVendor
	 * @param javaVendor
	 */
	public void setJavaVendor(String javaVendor) {
		this.javaVendor = javaVendor;
	}

	/**
	 * Getter for property javaVersion
	 * @return javaVersion
	 */
	public String getJavaVersion() {
		RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
		this.javaVersion= runtimeMXBean.getVmVersion();
		return this.javaVersion;
	}

	/**
	 * Setter for property javaVersion
	 * @param javaVersion
	 */
	public void setJavaVersion(String javaVersion) {
		this.javaVersion = javaVersion;
	}

	/**
	 * Getter for property javaVm
	 * @return javaVM
	 */
	public String getJavaVM() {
		RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
		this.javaVM = runtimeMXBean.getVmName();
		return javaVM;
	}
	
	/**
	 * Setter for property javaVM
	 * @param javaVM
	 */
	public void setJavaVM(String javaVM) {
		this.javaVM = javaVM;
	}

	/**
	 * Getter for property jvmVendor
	 * @return
	 */
	public String getJvmVendor() {
		return jvmVendor;
	}

	/**
	 * Setter for property jvmVendor
	 * @param jvmVendor
	 */
	public void setJvmVendor(String jvmVendor) {
		this.jvmVendor = jvmVendor;
	}

	/**
	 * Getter for property jvmVersion
	 * @return jvmVersion
	 */
	public String getJvmVersion() {
		return jvmVersion;
	}

	/**
	 * Setter for property jvmVersion
	 * @param jvmVersion
	 */
	public void setJvmVersion(String jvmVersion) {
		this.jvmVersion = jvmVersion;
	}

	/**
	 * Getter for property osArchitecture
	 * @return osArchitecture
	 */
	public String getOsArchitecture() {
		return osArchitecture;
	}

	/**
	 * Setter for property osArchitecture
	 * @param osArchitecture
	 */
	public void setOsArchitecture(String osArchitecture) {
		this.osArchitecture = osArchitecture;
	}

	/**
	 * Getter for property systemDate
	 * @return systemDate
	 */
	public Date getSystemDate() {
		return systemDate;
	}

	/**
	 * Setter for property systemDate
	 * @param systemDate
	 */
	public void setSystemDate(Date systemDate) {
		this.systemDate = systemDate;
	}

	/**
	 * Getter for property systemTime
	 * @return systemTime
	 */
	public String getSystemTime() {
		return systemTime;
	}

	/**
	 * Setter for property systemTime
	 * @param systemTime
	 */
	public void setSystemTime(String systemTime) {
		this.systemTime = systemTime;
	}

	/**
	 * Getter for property userName
	 * @return userName
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * Setter for property userName
	 * @param userName
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	/**
	 * This method navigates user to the previous page
	 * @return
	 */
	public String back(){
		return "adminConsole";
	}
}
